local ma__mengying = fk.CreateSkill {
  name = "ma__mengying",
}

Fk:loadTranslationTable{
  ["ma__mengying"] = "梦迎",
  [":ma__mengying"] = "每轮开始时，你可以秘密选择一名角色并记录其体力值，本轮结束时，你将手牌数调整至其体力上限并令其将体力值调整至记录值。",
  ["@@ma__mengying-round"] = "梦迎",

  ["#ma__mengying-choose"] = "梦迎：秘密选择一名角色，本轮结束时其调整至当前体力值",
  ["#ma__mengying-throw"] = "梦迎：将手牌调整至 %src 的体力上限（即弃置 %arg 张牌） ",
}

ma__mengying:addEffect(fk.RoundStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(ma__mengying.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, ma__mengying.name)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getAlivePlayers(),
      skill_name = ma__mengying.name,
      prompt = "#ma__mengying-choose",
      cancelable = false,
      no_indicate = true,
    })[1]
    room:setPlayerMark(player, "@@ma__mengying-round", {to.id, to.hp})
  end,
})

ma__mengying:addEffect(fk.RoundEnd, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@ma__mengying-round") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, ma__mengying.name, "special")
    local hp_record = player:getMark("@@ma__mengying-round")
    if type(hp_record) ~= "table" then return false end
    for _, p in ipairs(room:getAlivePlayers()) do
      if p.id == hp_record[1] then
        local p_record = hp_record
      if p_record then
        p.hp = math.min(p.maxHp, p_record[2])
        room:broadcastProperty(p, "hp")
        if player:getHandcardNum() < p.maxHp then
          player:drawCards((p.maxHp - player:getHandcardNum()), ma__mengying.name)
        elseif player:getHandcardNum() > p.maxHp then
          room:askToDiscard(player, {
          min_num = player:getHandcardNum() - p.maxHp,
          max_num = player:getHandcardNum() - p.maxHp,
          include_equip = false,
          skill_name = ma__mengying.name,
          cancelable = false,
          prompt = "#ma__mengying-throw:"..p.id.."::"..(player:getHandcardNum() - p.maxHp),
        })
        end
      end
      end
    end
  end,
})

return ma__mengying
